#ifndef WINDOW_H
#define WINDOW_H

#include <QtGui>
#include <QApplication>

class WT : public QWidget
{
	Q_OBJECT

private:
	int state;
	unsigned char memory[6];
	int period; // in ms
	int ledcolor;
	
	QLabel *Lstate;
	QLabel *Lperiod;
	QLabel *Lledcolor;
	QLabel *Lmemory;
	QLabel *Ltemperature;

	char *urbmsgs[4];
	QLabel *urb[4];

public: 
	WT(QWidget *parent=0);
	enum {STOP=0, START};
	enum {GREEN=0, YELLOW, OFF};
	float temperature;

public slots:
	void setstate(int state);
	int getstate();
	void setmemory(const unsigned char *memory, int len);
	void getmemory(unsigned char *buffer);
	void initialize();
	void setperiod(int period);
	int getperiod();
	void setledcolor(int ledcolor);
	int getledcolor();
	void getserial(char *buffer);
	void showtemperature();
	void showurb(char *data);
};

class TPGen;

class ReadURB : public QThread
{
	Q_OBJECT

	WT* window;
	int maxurb;
	void copewith(char buf[8], FILE *f);

	TPGen *tpgenthread;
	
public:
	ReadURB(WT *window, int maxurb = 0, QObject* parent = NULL);
	void run();

signals:
	void setstate(int state);
	int getstate();
	void setmemory(const unsigned char *memory, int len);
	void getmemory(unsigned char *buffer);
	void initialize();
	void setperiod(int period);
	int getperiod();
	void setledcolor(int ledcolor);
	int getledcolor();
	void getserial(char *buffer);
	void showurb(char *data);
};

/* temperature generator */
class TPGen : public QThread
{
	Q_OBJECT
	
	WT *window;
	FILE *f;
public:
	int live;
	int adjustT;
	TPGen(WT *window, QObject* parent = NULL);
	void run();

signals:
	void showtemperature();
};

/* counter_value is used as offset:1 of respond packet. */
int nextcountervalue();
#endif
